
-- 执行并返回execute命令的结果 [cmd:执行的命令行] [返回结果文本]
function execute(cmd)
    local iRet, sRet = pcall(function()
        local FileName = userPath() .. "/1.dump"
        cmd = cmd.." > " .. FileName
        local ret = os.execute(cmd)
        io.input(FileName)
        local ReadContent = io.read("*a")
        io.close()
        return ReadContent
	end)
	if iRet == true then
		return sRet
	else
		print(sRet)
		return ""
	end
end
-- [0]包名 [1]组件名 [nil]包名/组件名
function getTopActivity(mode)
	local iRet, sRet = pcall(function()
	local ret = execute("dumpsys activity top ")
		if ret ~= "" then
			if mode then
				if mode == 0 then
					return string.match(ret, "ACTIVITY ([^/]+)") 
				elseif mode == 1 then
					return string.match(ret, "ACTIVITY .-/([^ ]+)")
				end
			else
				return string.match(ret,"ACTIVITY ([^ ]+)")
			end
		end
	end)
	if iRet == true then
		return sRet
	else
		print(sRet)
		return ""
	end
end